package com.roncoo.ysq.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.ysq.entity.Adv;
import com.roncoo.ysq.service.IAdvService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuanshuaiqiang
 * @since 2021-03-24
 */
@Api(tags = "轮播图")
@RestController
@RequestMapping("/adv")
public class AdvController {

    @Resource
    private IAdvService advService;


    /**
     * 上传图片返回路径
     * @param file
     * @return
     */
    @ApiOperation("前台上传阿里云图片，返回路径 ")
    @PostMapping("getImgPath")
    public String getpath( MultipartFile file){
        String path=advService.getPath(file);
        return path;
    }
    @GetMapping("findAdv")
    public List<Adv> findAdv(){
        return advService.list();
    }



    /**
     * 查询数据
     */
    @ApiOperation("查询所有数据，包括分页，模糊查询")
    @PostMapping("findAll")
    public IPage<Adv> findAll(Page page,Adv adv){
        IPage<Adv> page1=advService.findAll(page,adv
        );
        return page1;
    }
    /**
     * 删除数据
     */
    @ApiOperation("根据传回的id删除数据")
    @GetMapping("del/{id}")
    public Boolean del(@PathVariable("id")Integer id){
        return advService.removeById(id);
    }
    /**
     * 添加数据
     */
    @ApiOperation("根据传回的对象来进行添加")
    @PostMapping("addData")
    public Boolean adddta(Adv adv){
        if(adv.getBeginTime()==""){
            adv.setBeginTime(null);
        }
        if(adv.getEndTime()==""){
            adv.setEndTime(null);
        }
        return advService.save(adv);
    }
    /**
     * 修改数据
     */
    @ApiOperation("根据传回的对象里的id进行修改")
    @PostMapping("updData")
    public Boolean updata(Adv adv){
        return advService.updateById(adv);
    }

    /**
     * before 状态查询
     */
    @ApiOperation("前端的查询正常状态的数据")
    @GetMapping("findByStatusId")
    public List<Adv> findByStatus(){
        List<Adv> all=advService.findByStatus();
        return all;
    }
}

